export enum EPluginKey {
  SELECTION = 'selection',
  //
  SNAPLINE = 'snapline',
  //
  TRANSFORM = 'transform',
  // scroller
  SCROLLER = 'scroller',
  // miniMap
  MINIMAP = 'miniMap',
  // history
  HISTORY = 'history',
  // keyboard
  KEYBOARD = 'keyboard',
  // clipboard
  CLIPBOARD = 'clipboard'
}

export enum EToolKey {
  // 上一步
  BACKWARD = 'backward',
  // 下一步
  FORWARD = 'forward',
  // 退出
  QUIT = 'quit',
  // 缩小
  ZOOMOUT = 'zoomout',
  // 放大
  ZOOMIN = 'zoomin'
}

export enum EPortName {
  LEFT = 'left',
  TOP = 'top',
  RIGHT = 'right',
  BOTTOM = 'bottom'
}

export enum EPopVisible {
  // 显示
  SHOW = 'show',
  // 隐藏
  HIDE = 'hide'
}

export enum EMenuItem {
  // 新增父节点
  PARENT = 'parent',
  // 新增子节点
  CHILD = 'child',
  // 编辑节点
  EDIT = 'edit',
  // 解除绑定
  UNEMBED = 'unembed'
}

export interface INode {
  // 节点是否正常使用
  enable: boolean
  // 节点属性是否可编辑
  editable?: boolean
  // 是否为容器节点
  container?: boolean
  type: string
  label: string
  resize?: boolean
  height?: number
  width?: number
  ports?: EPortName[] | Record<string, any>
  icon: string
  className?: string
  markup?: Record<string, any>
  attrs?: Record<string, any>
  // 业务数据。透传
  data?: Record<string, any>
}

export interface IDesignerContainer {
  // 画布容器
  graph: HTMLElement
  // 节点列表容器
  node: HTMLElement
  // 缩略图容器
  miniMap?: HTMLElement
}

export type TPluginValue = boolean | Function

// 使用类型别名定义映射类型
export type PluginMapping = {
  [K in EPluginKey]?: TPluginValue
}

// 修改 IPlugin 接口以使用 PluginMapping 类型
export interface IPlugin extends PluginMapping {}

export enum EDesignerEventKey {
  // node:dblclick
  NODE_DBLCLICK = 'node:dblclick',
  // node:click
  NODE_CLICK = 'node:click',
  // node:resizing
  NODE_RESIZING = 'node:resizing',
  // node:mouseenter
  NODE_MOUSEENTER = 'node:mouseenter',
  // node:mouseleave
  NODE_MOUSELEAVE = 'node:mouseleave',
  // node:added
  NODE_ADDED = 'node:added',
  // node:removed
  NODE_REMOVED = 'node:removed',
  // node:embedding
  NODE_EMBEDDING = 'node:embedding',
  // node:change
  NODE_CHANGE = 'node:change',
  // node:contextmenu
  NODE_CONTEXTMENU = 'node:contextmenu',
  // canUndo
  GRAPH_CAN_UNDO = 'canUndo',
  // canRedo
  GRAPH_CAN_REDO = 'canRedo',
  // backspace
  GRAPH_BACKSPACE = 'backspace'
}

export interface IDesignerOptions {
  debug?: boolean
  container: IDesignerContainer
  plugins?: IPlugin
  events?: {
    [EDesignerEventKey.NODE_DBLCLICK]?: Function
    [EDesignerEventKey.NODE_RESIZING]?: Function
    [EDesignerEventKey.NODE_ADDED]?: Function
    [EDesignerEventKey.NODE_REMOVED]?: Function
    [EDesignerEventKey.NODE_CHANGE]?: Function
    [EDesignerEventKey.NODE_CONTEXTMENU]?: Function
    [EDesignerEventKey.GRAPH_BACKSPACE]?: Function
    [EDesignerEventKey.GRAPH_CAN_UNDO]?: Function
    [EDesignerEventKey.GRAPH_CAN_REDO]?: Function
  }
}
